package com.example.token.configuration;

import com.example.token.interceptor.AuthorizationInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author cailei.lu
 * @description
 * @date 2018/8/3
 */
@Configuration
public class WebAppConfiguration implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new AuthorizationInterceptor()).addPathPatterns("/**"); //用拦截器的话需要此行代码；
        registry.addInterceptor(new AuthorizationInterceptor())
                .addPathPatterns("/**") //可以没有(默认拦截所有)
                .excludePathPatterns("/api/v1/login", "/user/hello")//放掉某些特定不需要校验token的路由
                .excludePathPatterns("/error", "/static/**","/my/**","/js/**")//

                .excludePathPatterns("/swagger-resources/**") // **/swagger-ui.html 放行
//                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg", "/**/*.jpeg", "/*.html", "/**/*.html","/swagger-resources/**")
        ;
    }

    /** https://blog.csdn.net/qq_22165667/article/details/84326592
     * 通过addResourceHandler添加映射路径，然后通过addResourceLocations来指定路径。
     * 我们访问自定义my文件夹中的elephant.jpg 图片的地址为 http://localhost:8080/my/elephant.jpg
     *      addResourceLocations指的是文件放置的目录，
     *      addResoureHandler指的是对外暴露的访问路径
     */
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry
//                .addResourceHandler("/my/**") // static/my;
//                .addResourceLocations("classpath:/my/");    // static/my;
//        //指定外部目录
//        // registry.addResourceHandler("/my/**").addResourceLocations("file:E:/my/");
//    }


}
